<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>升级任务管理</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0"> 
	<meta http-equiv="X-UA-Compatible" content="IE=edge" />
	<jsp:include page="../resource.jsp"></jsp:include>
	<script type="text/javascript">
	var ptId = '';  //单击选中的节点的ID
	$(document).ready(function() {
		var h = '85%';
 		if($.browser.msie && ($.browser.version == 8.0 || $.browser.version == 9.0)){
 	    	 h = $(self.parent.parent.frames['mainFrame']).height()-87; 
 	    }
        $('#upgradegrid').omGrid({
        	dataSource : 'upgrade!findAllJobs.do',
            height : h,
            limit : 20,
            showIndex : true,
            colModel : [ 
                        {header : '设备名称', name : 'objectName', width : 80, align : 'center'},
                         {header : 'GUID', name : 'guid', width : 100, align : 'center'},
                         {header : '任务执行方式', name : 'jobMode', width : 120, align : 'left' ,renderer : modelRenderer},
                         {header : '任务状态', name : 'jobStatus', width : 100, align : 'left',renderer : statusRenderer},
                         {header : '升级文件路径', name : 'fileName', width : 120, align : 'left'},
                         {header : '老版本号', name : 'oldVersion', width : 120, align : 'left'},
                         {header : '升级版本号', name : 'newVersion', width : 120, align : 'left'},
                         {header : '创建时间', name : 'createDatetime', width : 140, align : 'center'},
                         {header : '开始时间', name : 'startDownloadDatetime', width : 140, align : 'center'},
                         {header : '任务结束时间', name : 'finishDatetime', width : 140, align : 'center'},
                         {header : '启用状态', name : 'enable', width : 'autoExpand', align : 'left' ,renderer : stateRenderer} 
                         ]
        });
        
    $('#jobStatus').omCombo({
    	dataSource : 'upgrade!findJobStatus.do',
        onValueChange : function(target, newValue, oldValue) {
            $('#jobStatusId').val(newValue);
        }
    });
    $('#jobMode').omCombo({
    	dataSource : 'upgrade!findJobMode.do',
        onValueChange : function(target, newValue, oldValue) {
        	 $('#jobModeId').val(newValue);
        }
    });
    
    $("#addJobEditor").omDialog({
    	    autoOpen: false,
		    height: 350,
		    width : 480,
		    modal: true,
		    buttons: [{
            text : "确定", 
            click : function () {
              $("#addJobForm").submit();
            }
         }, {
            text : "取消", 
            click : function () {
              $("#addJobEditor" ).omDialog("close");
          }
      }]
    });
        
    $('#addJob').click(function(){
    	$("#addJobEditor").omDialog('open');
    	$("#addJobForm").resetForm();
    });
    $('#deleteJob').click(function(){
    	var selects = $("#upgradegrid").omGrid("getSelections",true);
    	if(selects.length <= 0){
    		$.omMessageBox.alert({content:'请您选择删除的记录'});
    		return;
    	}
    	 $.omMessageBox.confirm({
             title:'确认删除',
             content:'您确定删除该职务？',
             onClose:function(result){
            	 if(result){
            		 $.ajax({
            			 url : 'upgrade!deleteJob.do',
            	    	 data : {jobId : selects[0].id},
            			 success : function(data){
            				 if(data == '1'){
            					 $.omMessageTip.show({timeout : 2000,content : '删除成功！'});
            					 $('#upgradegrid').omGrid("reload");
            				 }else{
            					 $.omMessageTip.show({timeout : 2000,content : '删除失败！'});
            				 }
            			 }
            		 });
            	 }
             }
         });
    });
    
    var options  = {
  		  url : 'upgrade!saveJobs.do',
            success : function(data){
               	if(data == '1'){  
                   	$.omMessageTip.show({timeout : 2000,content : '保存成功！'});
                   	$('#addJobEditor').omDialog('close');
                   	$('#upgradegrid').omGrid("reload");
               	}else{
               		$.omMessageTip.show({timeout : 2000,content : '保存失败！',type : 'error'});
               	}
            }
  	  };
	  $('#addJobForm').submit(function() {
          $(this).omAjaxSubmit(options);
          return false;//返回false,阻止浏览器默认行为
    });
    
	function stateRenderer(v)
	{
		if(v){
			return "启用";
		}else{
			return "停用";
		}
	}
	
	function modelRenderer(v)
	{
		if(v == null) return "";
		return v.name;
	}
	function statusRenderer(v)
	{
		if(v == null) return "";
		return v.name;
	}
	if($('#startDownloadDatetime').next().attr('class') != 'om-calendar-trigger') {
		 $('#startDownloadDatetime').omCalendar({showTime : true});
	}
	 
	
	 $("#updateFileDialog").omDialog({
		    autoOpen: false,
		    height: 450,
		    width : 710,
		    modal: true,
		    buttons: [{
	        text : "确定", 
	        click : function () {
	        	var selects = $("#updateFilePath").omGrid("getSelections",true);
	        	$("#fileName").val(selects[0].path);
	        	$("#updateFileDialog" ).omDialog("close");
	        }
	     }, {
	        text : "取消", 
	        click : function () {
	          $("#updateFileDialog" ).omDialog("close");
	      }
	  	}]
	});
	 $("#fileName").click(function(){
		 if($("#updateFilePath").find('tr').length  == 0){
			 $('#updateFilePath').omGrid({
		        	dataSource : 'upgrade!findFiles.do',
		            height : '350',
		            limit : 10,
		            showIndex : true,
		            colModel : [ 
		                         {header : '名称', name : 'name', width : 120, align : 'center'},
		                         {header : '文件大小', name : 'size', width : 90, align : 'center' },
		                         {header : '上传时间', name : 'date', width : 140, align : 'center'},
		                         {header : '路径', name : 'path', width : 190, align : 'left'},
		                         ]
		        });
		 }
		 $("#updateFileDialog").omDialog('open');
	 });
	 	var tabId = self.parent.parent.frames['mainFrame'].$('#tabs').omTabs('getActivated');
		var s = "<script>function function_"+tabId+"(nodeData){$('#refName').val(nodeData.text);"+
		"$('#refId').val(nodeData.id);}<\/script>";
		$("#upgradegrid").after(s);
    });
	</script>  
  </head>
  <body>
    <div class="toolbar mar">
		         <a href="#" class="rbutton" id="addJob"><span><img src="../images/add.gif" width="14" height="14" /><ins>新增任务</ins></span></a>
		         <a  class="line"></A>
		         <a href="#" class="rbutton" id="deleteJob"><span><img src="../images/del.gif" width="14" height="14" /><ins>删除任务</ins></span></a>
	</div>
    <table id="upgradegrid"></table>
    
    <div id="addJobEditor" title="编辑任务" style="display: none;">
     <form id="addJobForm" method="post">
          <table width="100%" border="0" class="grid_layout" cellspacing="0">
             <tr>
               <td width="20%" align="right">老版本号：</td>
               <td width="68%" colspan="3">
                  <input type="text" id="oldVersion" name="uptd.oldVersion" class="input_text">
               </td>
             </tr>
             <tr>
               <td width="20%" align="right">升级版本号：</td>
               <td width="68%" colspan="3">
                  <input type="text" id="newVersion" name="uptd.newVersion" class="input_text">
               </td>
             </tr>
             <tr>
               <td width="20%" align="right">选择设备/终端：</td>
               <td width="68%" colspan="3">
                  <input type="hidden" id="refId" name="uptd.guid" value="">
                  <input type="text" id="refName" class="input_text" value="在右侧菜单选择" readonly="readonly"/>
               </td>
             </tr>
             <tr>
               <td width="20%" align="right">升级文件路径：</td>
               <td width="68%" colspan="3">
                  <input type="text" id="fileName" name="uptd.fileName" class="input_text" readonly="readonly">
               </td>
             </tr>
             <tr>
               <td width="20%" align="right">是否启用：</td>
               <td width="68%" colspan="3">
                  <select id="enable" name="uptd.enable" style="width: 175px">
                     <option value="1">启用</option>
                     <option value="0">停用</option>
                  </select>
               </td>
             </tr>
             <tr>
               <td width="20%" align="right">开始时间：</td>
               <td width="68%" colspan="3">
                  <input type="text" id="startDownloadDatetime" name="uptd.startDownloadDatetime">
               </td>
             </tr>
             <tr>
               <td width="20%" align="right">任务执行方式：</td>
               <td width="68%" colspan="3">
                  <input id="jobMode" name="jobMode">
                  <input id="jobModeId" name="jobModeId" type="hidden">
               </td>
             </tr>
           </table>
         </form>
   </div>
   
   <div id="updateFileDialog" title="选择文件" style="display: none;">
      <table id="updateFilePath"></table>
   </div>
  </body>
</html>
